#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include "threadtcpserver.h"
#include "socketwork.h"
#include "udpwork.h"
#include <QMainWindow>
#include <QPointer>

QT_BEGIN_NAMESPACE
namespace Ui
{
class MainWindow;
}
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
    void sendFile();
    void sendPic();
    bool GetLocalIP();
    void UDP_init();

    void ReadLoalPicAndShow();
signals:
    void disconnect_socket_signal(qintptr socketDescriptor);

    void send_TcpMessage_signal(qintptr socketDescriptor, const QString &data);

    void send_UdpMessage_signal(const QString &data);

    void send_Broadcast_signal();

    void send_File_signal(qintptr socket_desc, QString filename);

    void send_Pic_signal(qintptr socket_desc, QString filename);

    void Update_IP_signal(QString ip);

private slots:

    void detain_ClientIP_slot(QString rmoteIP);

    void process_new_connect_slot(qintptr socketDescriptor);

    void slot_ComboxChange(QString index);

    void preview_image_slot(QPixmap image);

    void on_Btn_send_clicked();

    void on_Btn_selectPath_clicked();

    void on_Btn_SystemInit_clicked();

    void on_Btn_OpenTCPServer_clicked();

    void on_Btn_CloseTCPServer_clicked();

    void on_Btn_TCPSendMeg_clicked();

    void on_Btn_UDPSendMeg_clicked();

    void on_Btn_getClientIP_clicked();

private:
    Ui::MainWindow *ui;
    QPointer<ThreadTcpServer> tcp_server;
    QPointer<SocketWork> socket_work;
    qintptr socket_desc;
    QString sendMegcls;

    QPointer<UDPWork> udp_work;
    QPointer<QThread> udp_thread;

    QString localIp;

};

Q_DECLARE_METATYPE(qintptr);
#endif // MAINWINDOW_H
